#ifndef H_RCGD_CONFIG_H
#define H_RCGD_CONFIG_H

#define		RUN_TEST	1
#define		RUN_NORMAL	0

#define		AGING_TEMP_CONTROL	1
#define		TEMP_CONTROL		0

#define		CONFIG_HEADER1	0x11
#define		CONFIG_HEADER2	0x22
#define		CONFIG_HEADER3	0x33
#define		CONFIG_HEADER4	0x44

#define		RUN_TEST	1
#define		RUN_NORMAL	0

#define		AGING_TEMP_CONTROL 1
#define		TEMP_CONTROL 0


typedef struct CONFIG_M{
    char			TimeMode;
    char            LOCALHOUR;
    char            LOCALMINUTE;

    long            ANTDLY;

    P_              POSITION;

	int				DAC;
	float			GAIN;

	UART_CONFIG_	SCC1,SCC2,SCC3;

	char			TEMPER_CONTROL;
	char			MASK;
	
    char			WriteEvent;
    char			WriteBackupEvent;

    int				VERSION;
    char			OCXO_ID[12];

	int				SectorWriteCounter;

	unsigned short	AlarmRange;
	unsigned short	HoldoverDuration;

	int				WarmStartLimit;

	char			PECL_CHECK_FLAG;

	char			AntCheckFlag;
	char			PositionMode;
	char			POSITION_FIX;

	char			beep_flag;
	char			openshort_flag;

	unsigned char	delay_value;
	int				HWrevision;
	
	float			E1_Accuracy;
	float			E1_Jitter_Boundary;

	int				RcvType;

	int				iPeriodUdpReport;
	int				iPeriodHeartBeat;

	double			iTemperatureGain;
	int 		    iCVType;
	double			PosX;
	double			PosY;
	double			PosZ;

	double 			SYSTEM_DELAY;
	int				FPGACH;
	int 				VMEMODE;
	int 				NETSEND;

} CONFIG_;


extern CONFIG_     CONFIG;

extern void Init_CONFIG();
extern void WriteCONFIG();
extern char ReadCONFIG();
extern void PresetCONFIG();
extern void Show_Config(void);

#define M_MAX_CF_STR_CNT	20
char cf_str_buf[M_MAX_CF_STR_CNT][100];

typedef struct CF_{
	int id;			//ID
	double v;		//Value
	char type;		//Type
	char *name;	//Name
	double min;		//Min
	double max;		//Max
	double dft;		//Default
}ConfigFormat;

#define CONFIG_INDEX	50
extern ConfigFormat cfConfig[ CONFIG_INDEX ];

enum ConfigDefine{ cTimeMode = 0, 
					cLOCALHOUR,
					cLOCALMINUTE, 
					cANTDLY,
					cAntCheckFlag,
					cPositionMode,
					cLAT,
					cLON,
					cHEI,
					cDAC,
					cGAIN,
					cMASK,
					cOCXO_PATH,
					cOCXO_ID,
					cOCXO_CID,
					cOCXO_TID,
					cAlarmRange,
					cHoldoverDuration,
					cWarmStartLimit,
					cbeep_flag,
					copenshort_flag,
					cdelay_value,
					cTEMPER_CONTROL,
					cWriteEvent,
					cHWrevision,
					cGPSRceiverType,
					cStatusReportPeriod,
					cHeartBeatPeriod,
					cTemperatureGain,
					cCVType,
					cPosX,
					cPosY,
					cPosZ,
					cSYSTEM_DELAY,
					cFPGACH,
					cVMEMODE,
					cNETSEND,
					cEnd
				};

void Setting_CONFIG(void);
void upper_str(char *Str);
void lower_str(char *Str);

#define CheckWithinTheConfigRange(v,index) \
	( ( cfConfig[index].min<= (v) ) && ( (v)<= cfConfig[index].max  ) )

long my_atoi(char *s);
long my_atol(char *s);
double my_atof(char *s);

#endif
